package com.example.su_shi_tan_core.db

import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.example.su_shi_tan_bas_lib.global.AppGlobals

@Database(entities = [UserInfoBeanWrapper::class],version = 1)
abstract class UserInfoDatabase : RoomDatabase() {

    companion object {

        @Volatile
        private var DATABASE: UserInfoDatabase? = null

        fun getInstance() = DATABASE ?: synchronized(this) {
            DATABASE ?: buildDataBase().also { DATABASE = it }
        }

        private fun buildDataBase() =
            Room.databaseBuilder(
                AppGlobals.getApplication(),
                UserInfoDatabase::class.java,
                "su_shi_tan_UserInfo"
            ).allowMainThreadQueries()
                .fallbackToDestructiveMigration()
                .build()
    }

    abstract fun getUserInfoDao():UserInfoDao

}